<?php /*a:2:{s:55:"F:\CaOadmin\application\admin\view\Admin\adminform.html";i:1569741248;s:37:"../application/admin/view/layout.html";i:1569485205;}*/ ?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title><?php echo htmlentities($title); ?></title>

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="favicon.ico">
    <link href="<?php echo staticResource('css/bootstrap.min.css?v=3.3.6'); ?>" rel="stylesheet">
    <link href="<?php echo staticResource('css/font-awesome.min.css?v=4.4.0'); ?>" rel="stylesheet">
    


    <link href="<?php echo staticResource('css/animate.css'); ?>" rel="stylesheet">
    <link href="<?php echo staticResource('css/style.css?v=4.1.0'); ?>" rel="stylesheet">
    <link href="<?php echo staticResource('extend/common.css'); ?>" rel="stylesheet">
</head>

<body class="fixed-sidebar full-height-layout gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">

  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-content">
          <form method="post" class="form-horizontal" id="admin-info">

            <?php if(!empty($data)): ?>
            <div class="form-group">
              <label class="col-sm-2 control-label">ID</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" value="<?php echo htmlentities($data['id']); ?>" name="id" readonly>
              </div>
            </div>
            <?php endif; ?>

            <!--编辑状态下的角色-->
            <?php if(!empty($data)): ?>
            <div class="form-group">
              <label class="col-sm-2 control-label">角色</label>
              <div class="col-sm-10 role-select">
                <?php foreach($data['role_id'] as $r_id): ?>
                <div class="input-group">
                  <select class="form-control inline" name="role_id[]">
                    <option value="0">角色</option>
                    <?php foreach($roles as $k =>$r): ?>
                    <option value="<?php echo htmlentities($k); ?>" <?php if($r_id == $k): ?> selected <?php endif; ?>><?php echo htmlentities($r); ?></option>
                    <?php endforeach; ?>
                  </select>
                  <span class="input-group-btn">
                    <button type="button" class="btn btn-primary add_role">+</button>
                  </span>
                </div>
                <?php endforeach; ?>
              </div>
            </div>
            <?php else: ?>
            <!--添加状态下的角色-->
            <div class="form-group">
              <label class="col-sm-2 control-label">角色</label>
              <div class="col-sm-10 role-select">
                <div class="input-group">
                  <select class="form-control inline" name="role_id[]">
                    <option value="0">角色</option>
                    <?php foreach($roles as $k => $r): ?>
                    <option value="<?php echo htmlentities($k); ?>"><?php echo htmlentities($r); ?></option>
                    <?php endforeach; ?>
                  </select>
                  <span class="input-group-btn">
                    <button type="button" class="btn btn-primary add_role">+</button>
                  </span>
                </div>
              </div>
            </div>
            <?php endif; ?>

            <div class="form-group">
              <label class="col-sm-2 control-label">登录名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" value="<?php echo empty($data) ? '' : $data['login_name']; ?>" name="login_name">
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">密码</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" value="" name="pwd">
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">手机</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" value="<?php echo empty($data) ? '' : $data['mobile']; ?>" name="mobile">
              </div>
            </div>


            <div class="form-group">
              <div class="col-sm-4 col-sm-offset-2">
                <button class="btn btn-primary" type="button" id="sub">保存</button>
              </div>
            </div>

          </form>
        </div>
      </div>
    </div>
  </div>

</div>


<!-- 全局js -->
<script src="<?php echo staticResource('js/jquery.min.js?v=2.1.4'); ?>"></script>
<script src="<?php echo staticResource('js/bootstrap.min.js?v=3.3.6'); ?>"></script>
<script src="<?php echo staticResource('js/plugins/metisMenu/jquery.metisMenu.js'); ?>"></script>
<script src="<?php echo staticResource('js/plugins/slimscroll/jquery.slimscroll.min.js'); ?>"></script>
<script src="<?php echo staticResource('js/plugins/layer/layer.min.js'); ?>"></script>
<script src="<?php echo staticResource('extend/common.js'); ?>"></script>

<!-- 自定义js -->

<script>
    $(function () {
        // 提交表单
        $('#sub').click(function () {
            http_post(
                "<?php echo url('admin/admin/save'); ?>",
                $('#admin-info').serialize(),
                function (res) {
                    layer.msg('保存成功',{icon:1},function () {
                        parent.location.reload();
                    })
                }
            )
            return false;
        })

        // 创建一个角色元素
        $('.role-select').on('click','.add_role',function () {
            var tmp = `
            <div class="input-group">
                  <select class="form-control inline" name="role_id[]">
                    <option value="0">角色</option>
                    <?php foreach($roles as $k => $r): ?>
                    <option value="<?php echo htmlentities($k); ?>"><?php echo htmlentities($r); ?></option>
                    <?php endforeach; ?>
                  </select>
                  <span class="input-group-btn">
                    <button type="button" class="btn btn-danger remove_role">&times;</button>
                    <button type="button" class="btn btn-primary add_role">+</button>
                  </span>
                </div>
            `;
            $(this).parents('div').eq(1).append(tmp);
        });

        // 移除一个角色元素
        $('.role-select').on('click','.remove_role',function () {
            $(this).parents('.input-group').remove();
        });
    })
</script>


</body>

</html>
